﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerCtrl : MonoBehaviour
{
    private Rigidbody rg;
    private int count;
    public Text countText;
    public Text tishi;

    // Start is called before the first frame update
    void Start()
    {
        count = 0;
        
        SetCountText();
        rg = this.GetComponent<Rigidbody>();

    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        rg.AddForce(new Vector3(h, 0, v));
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Block"))
        {
           
            Destroy(other.gameObject);
            count = count + 10;
            SetCountText();
        }

    }
   
    private void SetCountText()
    {
        countText.text = "分数:" + count.ToString();
        if (count >=120)
        {
            tishi.text = "你赢了";
        }
    }
}

